from google.appengine.ext import db
import geo.geomodel

class Member(db.Model):
    username = db.StringProperty(required=True)
    email = db.EmailProperty()
    salt = db.StringProperty()
    pwd = db.StringProperty()
    avatar = db.ReferenceProperty()
    join_date = db.DateTimeProperty(auto_now_add=True)
    following = db.StringListProperty() #list of member usernames
    skating_since = db.IntegerProperty(default=0)
    lives_in = db.StringProperty(default="")
    biography = db.TextProperty(default="")
    nickname = db.StringProperty(default="")
    uid = db.StringProperty(default="")
    profile_url = db.StringProperty(default="")
    access_token = db.StringProperty(default="")

class MemberFavorites(db.Model):
	username = db.StringProperty(required=True)
	favorites = db.StringListProperty() # list of favorite usernames
	
class MemberFavIndex(db.Model):
	favorited_by = db.StringListProperty() # list of member ids
	      
# menlo skate park: 37.451993,-122.176748  
class GeoSpot(geo.geomodel.GeoModel):
	name = db.StringProperty()
	desc = db.TextProperty(default="")
	added_by = db.ReferenceProperty()
	date_added = db.DateTimeProperty(auto_now_add=True)
	validated = db.BooleanProperty()
	features = db.IntegerProperty(default=0)
	tranny_features = db.IntegerProperty(default=0)
	street_features = db.IntegerProperty(default=0)
	longboard_features = db.IntegerProperty(default=0)
	misc_features = db.IntegerProperty(default=0)
	normalized_name = db.StringProperty()

class GeoSpotFavorites(db.Model):
	userid = db.IntegerProperty(required=True)
	favorites = db.ListProperty(long, default=None) # list of GeoSpot ids
		
class SpotValidation(db.Model):
    spot = db.ReferenceProperty(GeoSpot, collection_name="spot_validation_ref_set")
    validators = db.StringListProperty() # list of usernames that have validated this spot
    #validated_by_username = db.StringProperty()
    #validation_date = db.DateTimeProperty(auto_now_add=True)

class Comment(db.Model):
    spot = db.ReferenceProperty(GeoSpot, collection_name="comment_spot_ref_set")
    added_by = db.ReferenceProperty(Member, collection_name="comment_member_ref_set")
    timestamp = db.DateTimeProperty(auto_now_add=True)
    comment = db.StringProperty(multiline=True)

class Photo(db.Model):
    spot = db.ReferenceProperty(GeoSpot, collection_name="photo_spot_ref_set")
    added_by = db.ReferenceProperty(Member, collection_name="photo_member_ref_set")
    timestamp = db.DateTimeProperty(auto_now_add=True)
    image = db.ReferenceProperty()
    desc = db.StringProperty(multiline=True)
    
class PhotoComment(db.Model):
    photo = db.ReferenceProperty(Photo, collection_name="photo_comment_photo_ref_set")
    added_by = db.ReferenceProperty(Member, collection_name="photo_comment_member_ref_set")
    timestamp = db.DateTimeProperty(auto_now_add=True)
    comment = db.StringProperty()

class SkateSession(db.Model):
    spot = db.ReferenceProperty(GeoSpot, collection_name="skate_session_spot_ref_set")
    added_by = db.ReferenceProperty(Member, collection_name="skate_session_member_ref_set")
    timestamp = db.DateTimeProperty(auto_now_add=True)
    title = db.StringProperty()
    
class Activity(db.Model):
	type = db.StringProperty(required=True, choices=set(["join", "add_spot", "spot_comment", "spot_skate_session", "spot_photo", "spot_video"]))
	timestamp = db.DateTimeProperty(auto_now_add=True)
	member = db.ReferenceProperty(Member, collection_name="activity_member_ref_set")
	spot = db.ReferenceProperty(GeoSpot, collection_name="activity_spot_ref_set")
	photo = db.ReferenceProperty(Photo, collection_name="activity_photo_ref_set")
	comment = db.ReferenceProperty(Comment, collection_name="activity_comment_ref_set")
	
class Sk8Image(db.Model):
	timestamp = db.DateTimeProperty(auto_now_add=True)
	thumb = db.BlobProperty()		#48
	small = db.BlobProperty()		#64
	med = db.BlobProperty()			#128
	large = db.BlobProperty()		#604
	original = db.BlobProperty()	#original
	memcache_sizes = db.StringListProperty() #list of sizes available in memcache
	
class Advertisement(db.Model):
	timestamp = db.DateTimeProperty(auto_now_add=True)
	image_url = db.LinkProperty() # ad should be 280 x 290
	redirect_url = db.LinkProperty() # clicking on ad redirects here
	expires = db.DateTimeProperty()
